using System;
using System.Windows.Forms;

namespace Woz
{
    internal class ReorderControlAction : Woz.Action
    {
        public ReorderControlAction(Woz.ScreenThumbnailSlider pSlider, Woz.ScreenThumbnail pThumbnail, int pNewIndex)
        {
            // save the slider
            this.mSlider = pSlider;

            // save the thumbnail
            this.mThumbnail = pThumbnail;

            // save the new index
            this.mNewIndex = pNewIndex;

            // save the original index
            this.mOriginalIndex = pThumbnail.TabIndex;
        }

        /// <summary>
        /// gets the name of the tool this action belongs to none in this case
        /// </summary>
        public override string ToolName
        {
            get
            {
                return "";
            }
        }

        /// <summary>
        /// gets whether this action can be propagated or not
        /// </summary>
        public override bool Propagatable
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// reorders the control to the new position in its parent
        /// </summary>
        /// <param name="pScreen">not used for non propagateable action</param>
        protected override void OnExecute(Woz.Screen pScreen)
        {
            // move the screen thumbnail to the new index
            this.mSlider.ReorderScreenThumbnail(this.mThumbnail, this.mNewIndex);
        }

        /// <summary>
        /// reorders the control to its original position in its parent
        /// </summary>
        /// <param name="pScreen">not used for non propagateable action</param>
        protected override void OnUnExecute(Woz.Screen pScreen)
        {
            // move the screen thumbnail back to the original index
            this.mSlider.ReorderScreenThumbnail(this.mThumbnail, this.mOriginalIndex);
        }

        /// <summary>
        /// the flow layout panel
        /// </summary>
        private Woz.ScreenThumbnailSlider mSlider;

        /// <summary>
        /// the control that is being reordered
        /// </summary>
        private Woz.ScreenThumbnail mThumbnail;

        /// <summary>
        /// the original index of the control
        /// </summary>
        private int mOriginalIndex;

        /// <summary>
        /// the new index of the control
        /// </summary>
        private int mNewIndex;
    }
}
